﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Helpers;
using BaseTerminalProtocol.Authorizations;

namespace BaseTerminalProtocol.TerminalActions.Terminals
{
    public class GetTerminalInfo
    {
        /// <summary>
        /// Requests the get agent info.
        /// </summary>
        /// <param name="authorization">The authorization.</param>
        /// <returns></returns>
        public static XmlDocument RequestGetTerminalInfo(Authorizations.Authorization authorization)
        {
            XmlDocument doc = XMLGate.Request_INIT(authorization);
            XmlElement xmlRoot = doc.DocumentElement;

            XmlElement xmlTerminal = XMLHelper.newElement(doc, "terminals");
            XmlElement xmlGetTerminalInfo = XMLHelper.newElement(doc, "getTerminalInfo");

            xmlTerminal.AppendChild(xmlGetTerminalInfo);
            if (xmlRoot != null) xmlRoot.AppendChild(xmlTerminal);

            return doc;
        }

        /// <summary>
        /// Responses the get agent info.
        /// </summary>
        /// <returns></returns>
        public static XMLGate.GateResponse ResponseGetTerminalInfo()
        {
            try
            {
                var authorization=new Authorization();
                string request = "";
                var requestGetTerminalInfo = RequestGetTerminalInfo(authorization);
                var requestSend = XMLGate.Request_SEND(requestGetTerminalInfo, authorization.ServerUrl, out request);
                var response = new XMLGate.GateResponse(requestSend);
                return response;
            }
            catch (Exception ex)
            {
                Tools.Logger("GetTerminalInfo : " + ex.Message, "error", "ResponseGetTerminalInfo");
            }
            return null;
        }
    }
}
